package com.ruoyi.web.controller.weiriya;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.weiriya.domain.WSocketTwo;
import com.ruoyi.weiriya.service.IWSocketTwoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 插座信息Controller
 * 
 * @author ruoyi
 * @date 2023-08-16
 */
@Api(tags = "插座信息管理")
@RestController
@RequestMapping("/weiriya/two")
public class WSocketTwoController extends BaseController
{
    @Autowired
    private IWSocketTwoService wSocketTwoService;

    /**
     * 查询插座信息列表
     */
    @ApiOperation("获取插座信息列表")
    @PreAuthorize("@ss.hasPermi('weiriya:two:list')")
    @GetMapping("/list")
    public TableDataInfo list(WSocketTwo wSocketTwo)
    {
        startPage();
        List<WSocketTwo> list = wSocketTwoService.list(wSocketTwo.queryWrapper());
        return getDataTable(list);
    }

    /**
     * 初始化插座信息
     */
    @ApiOperation("初始化插座信息")
    @GetMapping("/initAll")
    public void initAll()
    {
        wSocketTwoService.initAll();
    }

    /**
     * 导出插座信息列表
     */
    @ApiOperation("导出插座信息列表")
    @PreAuthorize("@ss.hasPermi('weiriya:two:export')")
    @Log(title = "插座信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WSocketTwo wSocketTwo)
    {
        List<WSocketTwo> list = wSocketTwoService.list(wSocketTwo.queryWrapper());
        ExcelUtil<WSocketTwo> util = new ExcelUtil<WSocketTwo>(WSocketTwo.class);
        util.exportExcel(response, list, "插座信息数据");
    }

    /**
     * 导入插座信息列表
     */
    @ApiOperation("导入插座信息列表")
    @PreAuthorize("@ss.hasPermi('weiriya:two:import')")
    @Log(title = "插座信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<WSocketTwo> util = new ExcelUtil<WSocketTwo>(WSocketTwo.class);
        List<WSocketTwo> list = util.importExcel(file.getInputStream());
        return success(wSocketTwoService.saveBatch(list));
    }

    /**
     * 获取插座信息详细信息
     */
    @ApiOperation("获取插座信息详细")
    @ApiImplicitParam(name = "id", value = "插座信息ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:two:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wSocketTwoService.getById(id));
    }

    /**
     * 新增插座信息
     */
    @ApiOperation("新增插座信息")
    @PreAuthorize("@ss.hasPermi('weiriya:two:add')")
    @Log(title = "插座信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WSocketTwo wSocketTwo)
    {
        return toAjax(wSocketTwoService.save(wSocketTwo));
    }

    /**
     * 修改插座信息
     */
    @ApiOperation("更新插座信息")
    @PreAuthorize("@ss.hasPermi('weiriya:two:edit')")
    @Log(title = "插座信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WSocketTwo wSocketTwo)
    {
        return toAjax(wSocketTwoService.updateById(wSocketTwo));
    }

    /**
     * 删除插座信息
     */
    @ApiOperation("删除插座信息")
    @ApiImplicitParam(name = "ids", value = "插座信息ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:two:remove')")
    @Log(title = "插座信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(wSocketTwoService.removeByIds(ids));
    }




}
